/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * 模版内别名元素及与指标的对应关系
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="Rpt_Template_Indication")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class TemplateIndication implements Comparable<Object>, Serializable {
	
	private static final long serialVersionUID = -702781063751166458L;
	
	public static final int CELLTYPE_TEXT = 1;
	public static final int CELLTYPE_NUMBER = 2;
	public static final int CELLTYPE_DATETIME = 3;
	public static final int CELLTYPE_COMBO = 4;
	public static final int CELLTYPE_TEXTAREA = 5;

	@Id
	@Column(name="TI_GUID",length=38)
	@GenericGenerator(name="TemplateIndication-assigned",strategy="assigned")
	private String guid;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Template_GUID",nullable=true)
	private Template template;
	
	@Column(name="Alias_Name",length=50)
	private String alias_Name;
	
	@Column(name="Alias_ChineseName",length=50)
	private String alias_ChineseName;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Indication_GUID",nullable=true)
	private Indication indication;
	
	/**
	 * 该指标所关联的分类集,之间用逗号分割，最多10个
	 */
	@Column(name="Related_Catalog_GUID",length=400)
	private String related_Catalog_GUID;
	
	/**
	 * 单元格输入控件类型
	 *	1：text
	 *	2：textarea
	 *	3：datetime
	 *	4: combo1(只能选择)
	 *	5: combo2(可输入、也可选择)
	 *	6：combo3(autoComplete,autoFilter)
	 */
	@Basic
	private Integer cell_Type; 
	
	@Column(name="Cell_InputControl_Properties",length=400)
	private String cell_InputControl_Properties;
	
	@Column(name="Cell_ReadOnly")
	private Boolean readOnly;
	
	@Column(name="Cell_Hidden")
	private Boolean hiddened;

	@Basic
	private Double tabIndex;
	
	@Column(name="tableName",length=38)
	private String tableName;
	
	@Column(name="columnName",length=38)
	private String columnName;
	
	@Column(name="Alias_ColumnCode",length=50)
	private String alias_ColumnCode;
	
	@Transient
	public String getIndicationGuid() {
		if(indication != null){
			return indication.getGuid();
		}
		return "";
	}
	
	public void setIndicationGuid(String indicationGuid) {
		if(indicationGuid != null && indicationGuid.trim().length()>0){
			if(indication==null){
				indication = new Indication();
				indication.setGuid(indicationGuid);
			}else{
				indication.setGuid(indicationGuid);
			}
		}
	}
	
	public String getAlias_ColumnCode() {
		return alias_ColumnCode;
	}
	public void setAlias_ColumnCode(String alias_ColumnCode) {
		this.alias_ColumnCode = alias_ColumnCode;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getAlias_Name() {
		return alias_Name;
	}

	public void setAlias_Name(String alias_Name) {
		this.alias_Name = alias_Name;
	}

	public String getAlias_ChineseName() {
		return alias_ChineseName;
	}
	public void setAlias_ChineseName(String alias_ChineseName) {
		this.alias_ChineseName = alias_ChineseName;
	}
	
	public String getCell_InputControl_Properties() {
		return cell_InputControl_Properties;
	}

	public void setCell_InputControl_Properties(String cell_InputControl_Properties) {
		this.cell_InputControl_Properties = cell_InputControl_Properties;
	}

	public Integer getCell_Type() {
		return cell_Type;
	}

	public void setCell_Type(Integer cell_Type) {
		this.cell_Type = cell_Type;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public Indication getIndication() {
		return indication;
	}

	public void setIndication(Indication indication) {
		this.indication = indication;
	}

	public Boolean getHiddened() {
		return hiddened;
	}

	public void setHiddened(Boolean hiddened) {
		this.hiddened = hiddened;
	}

	public Boolean getReadOnly() {
		return readOnly;
	}

	public void setReadOnly(Boolean readOnly) {
		this.readOnly = readOnly;
	}

	public String getRelated_Catalog_GUID() {
		return related_Catalog_GUID;
	}

	public void setRelated_Catalog_GUID(String related_Catalog_GUID) {
		this.related_Catalog_GUID = related_Catalog_GUID;
	}

	public Double getTabIndex() {
		return tabIndex;
	}

	public void setTabIndex(Double tabIndex) {
		this.tabIndex = tabIndex;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}
	
	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		TemplateIndication myClass = (TemplateIndication) object;
		return new CompareToBuilder().append(this.related_Catalog_GUID, myClass.related_Catalog_GUID).append(this.tabIndex, myClass.tabIndex).append(this.alias_Name, myClass.alias_Name).append(this.cell_InputControl_Properties, myClass.cell_InputControl_Properties).append(this.guid, myClass.guid).append(this.readOnly, myClass.readOnly).append(this.hiddened, myClass.hiddened).append(this.cell_Type, myClass.cell_Type).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof TemplateIndication)) {
			return false;
		}
		TemplateIndication rhs = (TemplateIndication) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(this.related_Catalog_GUID, rhs.related_Catalog_GUID).append(this.tabIndex, rhs.tabIndex).append(this.alias_Name, rhs.alias_Name).append(this.cell_InputControl_Properties, rhs.cell_InputControl_Properties).append(this.guid, rhs.guid).append(this.readOnly, rhs.readOnly).append(this.hiddened, rhs.hiddened).append(this.cell_Type, rhs.cell_Type).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-1349401847, 1730624327).appendSuper(super.hashCode()).append(this.related_Catalog_GUID).append(this.tabIndex).append(this.alias_Name).append(this.cell_InputControl_Properties).append(this.guid).append(this.readOnly).append(this.hiddened).append(this.cell_Type).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("cell_InputControl_Properties", this.cell_InputControl_Properties).append("cell_Type", this.cell_Type).append("readOnly", this.readOnly).append("indicationGuid", this.getIndicationGuid()).append("tabindex", this.tabIndex).append("alias_Name", this.alias_Name).append("related_Catalog_GUID", this.related_Catalog_GUID).append("guid", this.guid).append("hiddened",this.hiddened).toString();
	}
}